<template>
  <a-modal
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-descriptions :title="formInfo.title">
      <a-descriptions-item label="创建时间">{{
        formInfo.createTime
      }}</a-descriptions-item>
      <a-descriptions-item label="计划名称">{{
        formInfo.maintenanceName
      }}</a-descriptions-item>
      <a-descriptions-item label="保养模板">{{
        formInfo.maintenanceTemplateId
      }}</a-descriptions-item>
      <a-descriptions-item label="保养周期">{{
        formInfo.maintenanceCycle
      }}</a-descriptions-item>
      <a-descriptions-item label="保养类型">{{
        formInfo.maintenanceType
      }}</a-descriptions-item>
      <a-descriptions-item label="保养人">{{
        formInfo.maintenancePersonnel
      }}</a-descriptions-item>
      <a-descriptions-item label="计划编号">{{
        formInfo.maintenanceNo
      }}</a-descriptions-item>
      <a-descriptions-item label="是否启用true=启用false=禁用">{{
        formInfo.planStatus
      }}</a-descriptions-item>
      <a-descriptions-item label="最后执行时间">{{
        formInfo.finalExecutionTime
      }}</a-descriptions-item>
      <a-descriptions-item label="下次执行时间">{{
        formInfo.nextExecutionTime
      }}</a-descriptions-item>
      <a-descriptions-item label="保养次数">{{
        formInfo.maintenanceCount
      }}</a-descriptions-item>
      <a-descriptions-item label="计划类型">{{
        formInfo.planType
      }}</a-descriptions-item>
      <a-descriptions-item label="保养级别">{{
        formInfo.maintenanceLevel
      }}</a-descriptions-item>
    </a-descriptions>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { getAction } from '@/api/manage'

export default {
  name: 'DevMaintenancePlanView',
  components: {},
  data() {
    return {
      visible: false,
      confirmLoading: false,
      formInfo: {},
      url: {
        saveInfo: '/system/devMaintenancePlan/save',
        getInfo: '/system/devMaintenancePlan/info',
      },
    }
  },
  created() {},
  methods: {
    show(record) {
      this.formInfo = Object.assign({}, record)
      if (this.formInfo.id) {
        getAction(this.url.getInfo, { id: record.id }).then((res) => {
          this.$nextTick(() => {
            this.formInfo = pick(
              res.result.data,
              'id',
              'createTime',
              'maintenanceName',
              'maintenanceTemplateId',
              'maintenanceCycle',
              'maintenanceType',
              'maintenancePersonnel',
              'maintenanceNo',
              'planStatus',
              'finalExecutionTime',
              'nextExecutionTime',
              'maintenanceCount',
              'planType',
              'maintenanceLevel'
            )
          })
        })
      }
      this.visible = true
    },
    // 确定
    handleSubmit() {
      this.visible = false
    },
    // 关闭
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>
